<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<style>
    .mxnW{
        width: 80%;
        margin: 0 auto;
        margin-top: 20px;
    }
    .hidden{
        display: none;
    }
</style>
<body>
<!--//添加项目-->
<form class="layui-form mxnW" id="addProject" >
    <div class="layui-form-item">
        <label class="layui-form-label">选择团队</label>
        <div class="layui-input-block">
            <select name="" lay-verify="required" lay-search id="teamToProject">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目名称</label>
        <div class="layui-input-block">
            <input type="text" name="" id="title" required  lay-verify="required" placeholder="请输入团队名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">项目主页</label>
        <div class="layui-input-block">
            <textarea name="" id="wiki"  placeholder="请输入wiki或者项目主页" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">项目要求</label>
        <div class="layui-input-block">
            <textarea name="" id="need"  placeholder="请输入要求内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <div class="layui-input-block">
            <button style="margin-top: 10px" class="layui-btn" onclick="createProject()">立即创建</button>
        </div>
    </div>
</form>
<script src="../../public/js/jquery.min.js"></script>
<script>
    $.ajax({
        type: 'POST',
        url:"/team/search",
        data: {data:{key:'userid',value:JSON.parse(sessionStorage.user).userid}},
        success:function (data) {
            console.log(data)
            for(var i=0;i<data.result.length;i++){
                $("#teamToProject").append(
                    '<option value='+data.result[i].teamid+'>'+data.result[i].title+'</option>'
                )
            }
        } ,
        error:function () {
            layer.msg("系统错误")
        }
    })
</script>

<script src="./layui/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(tpl){
    });
    layui.use('upload', function(){
        layui.upload({
            url: '/ueditor/ue?action=uploadimage'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(res.state=="SUCCESS"){
                    layer.msg('上传成功')
                    $("#setImg").attr("src",location.origin+res.url)
                }else{
                    layer.msg('上传失败')
                }
            }
        });
    });
    function addProject() {
        $("#addProject").toggleClass("hidden");
    }
    function createProject() {
        var pdata={
            teamid:$("#teamToProject").val(),
            title : $("#title").val(),
            wiki : $("#wiki").val(),
            need :$("#need").val(),
            noteList : JSON.stringify({}),
        }
        $.ajax({
            type:'POST',
            url:"/project/create",
            data: {data:pdata},
            success:function (data) {
                if(data.msg.type==1){
                    console.log(data);
                }
            },
            error:function () {
            }
        });
    }
</script>
</body>
</html>